/**
 * Created by Administrator on 2018/3/20 0020.
 */

pay = function (value, row, index) {
    var pay = row.payType;
    if (pay == 1) {
        return [
            '<div><span >' + '支付宝' + '</span></div> '
        ].join('');
    } else {
        return [
            '<div ><span >' + '微信' + '</span></div> '
        ].join('');
    }
};

operate = function (value, row, index) {
    return [
        '<div><a href="javascript:void(0);" class="orderDetails" >' + '订单详情' + '</a>' +
        // '&nbsp;&nbsp;' +
        // '<a href="javascript:void(0);" class="orderComment" >' + '订单评论' + '</a>' +
        '</div> '
    ].join('');
};

operateEvents = {
    'click .orderDetails': function (e, value, row, index) {
        showModel("findOrderDetail-div", function () {
            var url = $().AbsUrlParse("/web/order/queryReservationOrder?orderNumber=" + row.orderNumber);
            var table = $("#reservationOrder");
            table.bootstrapTable("refresh", {url: url});
            showPic = function (value, row, index) {
                var img = row.head_pic;
                var imgUrl = "";
                if (img != null && img != '') {
                    imgUrl = File_Download_Url + img;
                    return [
                        '<image src=' + imgUrl + ' style="width:80px;height:80px" onclick="enlargeImage(this)"/>'
                    ].join('');
                } else {
                    return [
                        '<image src=' + $().AbsUrlParse("/static/images/no.png") + ' style="width:80px;height:80px" onclick="enlargeImage(this)"/>'
                    ].join('');
                }
            };
            orderState = function (value, row, index) {
                var state = row.orderState;
                if (state == 0) {
                    return [
                        '<span>' + '未消费' + '</span>'
                    ].join('');
                } else if (state == 1) {
                    return [
                        '<span>' + '用户确认' + '</span>'
                    ].join('');
                } else if (state == 2) {
                    return [
                        '<span>' + '商家确认' + '</span>'
                    ].join('');
                } else {
                    return [
                        '<span>' + '已退款' + '</span>'
                    ].join('');
                }
            };
            confirmTime = function (value, row, index) {
                var time = row.userConsumeTime;
                if (time != null) {
                    return [
                        '<span>' + time + '</span>'
                    ].join('');
                } else {
                    return [
                        '<span>' + '未确认' + '</span>'
                    ].join('');
                }
            }
        })
    },
    'click .orderComment': function (e, value, row, index) {
        showModel("orderComment-div", function () {
            var url = $().AbsUrlParse("/web/order/queryOrderComment?orderId=" + row.id);
            var table = $("#orderComment");
            table.bootstrapTable("refresh", {url: url});
            showImag = function (value, row, index) {
                var img = row.images;
                var imgUrl = "";
                if (img != null && img != '') {
                    imgUrl = File_Download_Url + img;
                    return [
                        '<image src=' + imgUrl + ' style="width:80px;height:80px" />'
                    ].join('');
                } else {
                    return [
                        '<image src=' + $().AbsUrlParse("/static/images/no.png") + ' style="width:80px;height:80px" />'
                    ].join('');
                }
            }
        });
    }
};


var queryAppointmentOrder = function () {
    var name = $("#nameBusiness").val();
    var nameUser = $("#nameUser").val();
    var orderId = $("#orderId").val();
    var select = $("#select").val();
    var url = $().AbsUrlParse("/web/order/queryAppointmentOrder?userName=" + nameUser + "&busName=" + name + "&orderId=" + orderId + "&state=" + select);
    var table = $("#table");
    table.bootstrapTable("refresh", {url: url});
};


orderState = function (value, row, index) {
    var s = "";
    if (row.orderState == 1) {
        s = "待付款";
    } else if (row.orderState == 2) {
        s = "待消费";
    } else if (row.orderState == 3) {
        s = "待配送";
    } else if (row.orderState == 4) {
        s = "配送中";
    } else if (row.orderState == 5) {
        s = "待评价";
    } else if (row.orderState == 6) {
        s = "已完结";
    } else if (row.orderState == 7) {
        s = "申请退款";
    } else if (row.orderState == 8) {
        s = "拒绝接单";
    } else if (row.orderState == 9) {
        s = "同意退款";
    } else if (row.orderState == 10) {
        s = "拒绝退款";
    } else if (row.orderState == 11) {
        s = "用户取消";
    } else if (row.orderState == 12) {
        s = "待取货";
    }
    return [
        '<div><span >' + s + '</span></div> '
    ].join('');

};

function enlargeImage(value) {
    showModel("detailImage-div", function () {
        var imgs = '<image src=' + value.src + ' style="height:500px" />';
        $("#image").html(imgs);
    })
}